#include "qdesignerwidget.h"

#include "qwidgetboxview.h"
#include "qformwidgetview.h"
#include "qpropertyview.h"
#include "qobjectlistwidget.h"
#include "qformwidget.h"


#include "../../libs/corelib/minisplitter.h"
#include "../../libs/sharedLib/qprojectcore.h"
#include "../../libs/sharedLib/qcommonstruct.h"

#include <QVBoxLayout>

QDesignerWidget::QDesignerWidget(QWidget *parent) :
    CORELIB::QAbstractPageWidget(parent),
    m_widgetBox(new QWidgetBoxView),
    m_formWidgetView(new QFormWidgetView),
    m_propertyView(new QPropertyView),
    m_objectWidget(new QObjectListWidget)
{
    QVBoxLayout *l=new QVBoxLayout;

    l->setMargin(0);
    l->setSpacing(0);



    CORELIB::MiniSplitter *splitter=new CORELIB::MiniSplitter(Qt::Horizontal);

    l->addWidget(splitter);


    splitter->addWidget(m_widgetBox);
    splitter->addWidget(m_formWidgetView);

    CORELIB::MiniSplitter *s=new CORELIB::MiniSplitter(Qt::Vertical);
    s->addWidget(m_propertyView);
    s->addWidget(m_objectWidget);
    splitter->addWidget(s);

    splitter->setStretchFactor(0,0);
    splitter->setStretchFactor(1,1);
    splitter->setStretchFactor(2,0);



    this->setLayout(l);

    connect(m_formWidgetView,SIGNAL(selectWidget(QWidget*)),m_propertyView,SLOT(selectWidget(QWidget*)));
    connect(m_objectWidget,SIGNAL(widgetSelect(QWidget*)),m_formWidgetView,SLOT(widgetSelect(QWidget*)));
    connect(m_formWidgetView,SIGNAL(selectWidget(QWidget*)),m_objectWidget,SLOT(selectWidget(QWidget*)));
    connect(m_formWidgetView,SIGNAL(clear_object_list()),m_objectWidget,SIGNAL(clear_object_list()));

    connect(m_formWidgetView,SIGNAL(formAddSignal(QWidget*)),m_objectWidget,SIGNAL(formAddSignal(QWidget*)));
    connect(m_formWidgetView,SIGNAL(addWidgetSignal(QWidget*,int)),m_objectWidget,SIGNAL(addWidgetSignal(QWidget*,int)));
    connect(m_formWidgetView,SIGNAL(widgetRemove(QWidget*)),m_objectWidget,SIGNAL(widgetRemove(QWidget*)));
    connect(m_formWidgetView,SIGNAL(showFormSignal(QWidget*)),this,SLOT(formChanged(QWidget*)));

    connect(m_formWidgetView,SIGNAL(need_make_page_position()),this,SLOT(make_page_position()));
    connect(m_propertyView,SIGNAL(need_make_page_position()),this,SLOT(make_page_position()));
}

void QDesignerWidget::formChanged(QWidget* wid)
{
}

void QDesignerWidget::make_page_position()
{
    tagPagePositionInfo info;
    info.m_data.insert("page_name",property("page_position"));
    QVariant v;
    v.setValue<tagPagePositionInfo>(info);
    m_propertyView->page_position(v);
    m_formWidgetView->make_page_position(v);


    m_propertyView->set_page_position(v);
    m_formWidgetView->set_page_position(v);
}

bool QDesignerWidget::pagePosition(const QVariant &param)
{
    bool ret=false;
    if(m_propertyView->pagePosition(param))
    {
        ret=true;
    }

    if(m_formWidgetView->page_position(param))
    {
        ret=true;
    }

    return ret;
}
